package com.guigu.tms.oms.plugin;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;

import java.util.Collections;

/**
 * mybatisplus 代码生成插件
 */
public class MybatisPlusGenerator {

    //ip地址
    private static String ip="119.23.228.22";

    //端口
    private static String port="3306";

    //数据库名称
    private static String database="pd_aggregation";

    //用户名
    private static String username="root";

    //密码
    private static String password="guigu123";

    //作者
    private static String author="zwj";


    public static void main(String[] args) {

        String projectPath=System.getProperty("user.dir");
        String constr="jdbc:mysql://"+ip+":"+port+"/"+database+"?useUnicode=true&characterEncoding=UTF-8&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC";

        FastAutoGenerator.create(constr, username, password)
                .globalConfig(builder -> {
                    builder.author(author) // 设置作者
//                            .enableSwagger() // 开启 swagger 模式
                            .fileOverride() // 覆盖已生成文件
                            .outputDir(projectPath+"/tms_oms/src/main/java/"); // 指定输出目录
                })
                .packageConfig(builder -> {
                    builder.parent("com.guigu.tms.oms") // 设置父包名
                            .pathInfo(Collections.singletonMap(OutputFile.xml,projectPath+"/tms_oms/src/main/java/com/guigu/tms/oms/mapper")); // 设置mapperXml生成路径
                })
                .strategyConfig(builder -> {
                    builder
                            //.likeTable(null) //全部表
                            .addInclude("pd_transport_order") // 设置需要生成的表名
                            .addTablePrefix("pd_", "d_") // 设置过滤表前缀
                            .mapperBuilder()
                            .enableMapperAnnotation();
                })
                .templateEngine(new FreemarkerTemplateEngine())
                .execute();
    }
}
